package com.morehair.controller.admin;

import com.morehair.bean.bo.admin.CreateGoodsBo;
import com.morehair.bean.bo.admin.GoodsBo;
import com.morehair.bean.bo.admin.UpdateGoodsBo;
import com.morehair.bean.vo.admin.BaseRespVo;
import com.morehair.bean.vo.admin.CatAndBrandVo;
import com.morehair.bean.vo.admin.DetailOfGoodsVo;
import com.morehair.bean.vo.admin.GoodsDataVo;
import com.morehair.service.admin.GoodsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * Description: 商品管理
 * Date: 2021/6/5
 * Time: 19:31
 * author: zhang wei
 */
@RestController
@RequestMapping("admin/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @RequestMapping("list")
    @RequiresPermissions("admin:goods:list")
    public BaseRespVo getGoodsList(Integer page, Integer limit, Integer goodsSn, String name, String sort, String order){
        GoodsDataVo goodsDataVO =  goodsService.getGoodsList(page,limit, goodsSn,name,sort,order);
        System.out.println(goodsDataVO);
        return BaseRespVo.ok(goodsDataVO);
    }

    @RequestMapping("create")
    @RequiresPermissions("admin:goods:create")
    public BaseRespVo createGoods(@RequestBody CreateGoodsBo createGoodsBo){
        boolean success = goodsService.createGoods(createGoodsBo);
        return BaseRespVo.ok();
    }

    @RequestMapping("update")
    @RequiresPermissions("admin:goods:update")
    public BaseRespVo updateGoods(@RequestBody UpdateGoodsBo updateGoodsBo){
        goodsService.updateGoods(updateGoodsBo);
        return BaseRespVo.ok();
    }

    @RequestMapping("delete")
    @RequiresPermissions("admin:goods:delete")
    public BaseRespVo deleteGoods(@RequestBody GoodsBo goodsBo){
        boolean success = goodsService.deleteGoodsById(goodsBo);
        return success ? BaseRespVo.ok() : BaseRespVo.fail("该条商品信息不存在");
    }

    @RequestMapping("detail")
    @RequiresPermissions("admin:goods:detail")
    public BaseRespVo detailOfGoods(Integer id){
        DetailOfGoodsVo detailOfGoodsVo = goodsService.detailOfGoods(id);
        return BaseRespVo.ok(detailOfGoodsVo);
    }


    @RequestMapping("catAndBrand")
    @RequiresPermissions("admin:goods:catAndBrand")
    public BaseRespVo selectCatAndBrand(){
        CatAndBrandVo catAndBrandVo = goodsService.selectCatAndBrand();
        return BaseRespVo.ok(catAndBrandVo);
    }

}
